package com.controller;

import com.model.Users;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by admin on 2017/3/3.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String userLogin(Users users, HttpServletRequest request) {
        boolean isVal = userService.hasMatchUser(users.getUser_name(), users.getPwd());
        if (isVal) {
            try {
                Users usersParam=userService.finUserByUserName(users.getUser_name());
                userService.loginSuccess(usersParam);
                return "/index";
            } catch (Exception e) {
                request.setAttribute("error", "登录失败!");
                return "/login";
            }
        } else {
            request.setAttribute("error", "登录失败!");
            return "/login";
        }

    }


}
